package com.k7.mobile.platform.web.interceptor;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.StrutsStatics;

import com.k7.mobile.platform.bo.IUserBO;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.qike.java.pojo.User;

public class LoginInterceptor extends AbstractInterceptor {
	private static final long serialVersionUID = 6301129967419590955L;
	private IUserBO userBO;
	
	public void setUserBO(IUserBO userBO) {
		this.userBO = userBO;
	}

	@Override
	public String intercept(ActionInvocation invocation) throws Exception {		
		ActionContext actionContext = invocation.getInvocationContext();   
		HttpServletRequest request= (HttpServletRequest) actionContext.get(StrutsStatics.HTTP_REQUEST);   
		Map session = actionContext.getSession();  
		
		User u = userBO.isLogin(request);
		if (u != null){
			return invocation.invoke();
		}else{
			return Action.LOGIN;
		}
	}
}
